﻿// -----------------------------------------------------------------------
// <copyright file="BowlusContainer.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Bowlus.Common
{
    using Microsoft.Practices.ServiceLocation;
    using Microsoft.Practices.Unity;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class BowlusContainer
    {
        private static readonly object LockObject = new object();

        private static volatile IServiceLocator currentContainer;

        public static IServiceLocator Current
        {
            get
            {
                CreateCurrentContainerIfNotCreated();
                return currentContainer;
            }

            set
            {
                lock (LockObject)
                {
                    currentContainer = value;
                }
            }
        }

        private static void CreateCurrentContainerIfNotCreated()
        {
            if (currentContainer == null)
            {
                lock (LockObject)
                {
                    if (currentContainer == null)
                    {
                        currentContainer = new UnityServiceLocator(new UnityContainer());
                    }
                }
            }
        }
    }
}
